package com.ymdx.service.impl;

import com.ymdx.entity.Verification;
import com.ymdx.service.VerificationService;
import org.springframework.stereotype.Service;
import org.springframework.transaction.annotation.Transactional;

import java.util.List;

/**
 * Created by yangliwei on 2017/8/13.
 */
@SuppressWarnings("ALL")
@Service("verificationService")
@Transactional
public class VerificationServiceImpl extends BaseServiceImpl<Verification,Long>implements VerificationService{

    @Override
    public Verification getByMobileCode(String mobile, String code) {
        String hql ="from Verification where mobile = ? and verificationCode =? and valid = true";
        List<Verification> result = (List<Verification>) hibernateTemplate.find(hql,mobile,code);
        if(result.isEmpty()){
            return null;
        }
        return result.get(0);
    }

    @Override
    public Verification getByMobile(String mobile) {
        String hql ="from Verification where mobile = ?  and valid = true order by createTime";
        List<Verification> result = (List<Verification>) hibernateTemplate.find(hql,mobile);
        if(result.isEmpty()){
            return null;
        }
        return result.get(0);
    }


}
